<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<script type="text/javascript" language="javascript">
<!--
function check_editright_info(thisForm)
{
	$("#stat").css({"display":"block"});
	$("#stat").html("正在保存内容......");
	_ajax_submit(thisForm, on_success, on_failure);
	return false;
}

function on_success(response)
{
	response1 = eval("("+response+")");
	var stat = document.getElementById("stat");
	if(response1.result == 'ok')
	{
		alert(response1.sucmsg);
		stat.innerHTML = "OK，正在重定向......";
		reloadPage();
	}
	else if(response1.result == 'error')
	{
		stat.innerHTML = response1.errmsg;
	}
}

function on_failure(response)
{
	var stat = document.getElementById("stat");
	stat.innerHTML = response;
}
-->
</script>
<div id="stat" style="display:none;"></div>
<form action="index.php" method="post" onsubmit="javascript:return check_editright_info(this);">
<table style="margin-top:20px;" width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#4c4c4c">
<tr>
<td>角色名</td>
<?php
foreach($operations_arr as $v)
{
	echo "<td>{$v['o_alias']}</td>";
}
?>
</tr>
<?php 
$operations = array();
foreach($roles_arr as $v)
{
	echo "<tr>";
	echo "<td>{$v['r_alias']}</td>";
	
	$operations = explode(',',$v['r_operation']);
	foreach($operations_arr as $v1)
	{
		if(in_array($v1['o_operation'], $operations))
		{
			$enable = ($v['r_role'] == 'unassign' || $v['r_role'] == 'admin') ? "disabled='disabled'" : "";
			
			echo "<td><input $enable type='checkbox' name='{$v['r_role']}_{$v1['o_operation']}' id='{$v['r_role']}_{$v1['o_operation']}' value='{$v1['o_operation']}' checked='checked'/></td>";
		}
		else
		{
			$enable = ($v['r_role'] == 'unassign' || $v['r_role'] == 'admin') ? "disabled='disabled'" : "";
			echo "<td><input $enable type='checkbox' name='{$v['r_role']}_{$v1['o_operation']}' id='{$v['r_role']}_{$v1['o_operation']}' value='{$v1['o_operation']}'/></td>";
		}
	}
	echo "</tr>";
}
?>
</table>
<input type="hidden" name="_m" value="<?php echo $next_controller;?>"/>
<input type="hidden" name="_a" value="<?php echo $next_action;?>"/>
<input type="submit" value="修改"/>
<input type="reset" value="重置"/>
</form>
<p style="font-size:12px;font-weight:bold;">*建议：角色所能完成任务情况下给予最小授权操作</p>